package com.lineengine.lineengine.node;


import com.lineengine.lineengine.context.IContext;
import com.lineengine.lineengine.result.DefaultResult;
import com.lineengine.lineengine.result.IResult;

/**
 * AbstractConditionalRollbackNode
 *
 * @author wenrong.yu
 */
public abstract class AbstractConditionalRollbackNode<T extends IContext<T>> extends AbstractRollbackNode<T> implements IPredicate<T> {
    @Override
    public final IResult<T> execute(T context) {
        return processWithRecordCostTime(context, () -> {
            if (!apply(context)) {
                return DefaultResult.success();
            }
            return super.execute(context);
        });
    }
}
